package com.haixiaoke.flat.bill.controller;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.bill.domain.Bill;
import com.haixiaoke.saas.bill.service.IBillService;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.token.FrontTokenComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author panda
 * @Date 2025/7/10
 **/
@RestController
@RequestMapping("/front/flat/bill/bill")
public class FlatBillController extends BaseController {
    @Autowired
    private IBillService billService;
    @Autowired
    private FrontTokenComponent frontTokenComponent;

    /**
     * 查询账单列表
     */
    @AuthCheck
    @GetMapping("/page")
    public TableDataInfo list(Bill bill) {
        startPage();
        bill.setConUserId(frontTokenComponent.getUserIdNotNull());
        List<Bill> list = billService.selectBillList(bill);
        return getDataTable(list);
    }

    @GetMapping("/{billId}")
    public AjaxResult getInfo(@PathVariable String billId) {
        return success(billService.selectBillByBillId(billId));
    }

    /**
     * 支付账单
     * @param billId
     * @return
     */
    @AuthCheck
    @GetMapping("/pay/{billId}/{payType}")
    public AjaxResult pay(@PathVariable String billId, @PathVariable("payType") String payType) {
        return billService.payBill(billId, frontTokenComponent.getUserIdNotNull(), payType);
    }
}
